<?php
/**
 * Programs is a widget that prepares programs listing in the layout
 */
class UPrograms extends CWidget
{
	private $_model=null;


	public function init()
	{	
		$model=$this->loadModel();
		if(empty($model->programs)){
			$q = '0';
		}else{
			$q = implode(" OR id = ", json_decode($model->programs));
		}
		$this->render('programs',array('models'=>Programs::model()->findAll('id = '.$q)));
		
	}
	
	/**
	 * Returns the data model based on the primary key given in the GET variable.
	 * If the data model is not found, an HTTP exception will be raised.
	 */
	private function loadModel()
	{
		if($this->_model===null)
		{
		    $criteria ='user='.Yii::app()->user->id;
		    $this->_model=Userdata::model()->find($criteria);

		    if($this->_model===null){
		        $this->_model=new Userdata;
		        $this->_model->user=Yii::app()->user->id;
		        $this->_model->save();
		    }
		}
		return $this->_model;
	}
}
?>




